<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>

<html>
<head>
    <title>登录页</title>
    <%--echart线图、柱状图、饼图等各种图型库 cdn--%>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts/dist/echarts.min.js"></script>
    <%--jquery cdn--%>
    <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.js"></script>
</head>
<body>
是否昨日新增<select name="yesterday">
    <option value="0">否</option>
    <option value="1">是</option>
</select>

<button onclick="zxt3()">点击展示折线图</button>


<div id="main" style="height: 500px;width: 500px"></div>
</body>
<script>

    function zxt3() {
        let yesterday = $("[name=yesterday]").val();
        $.ajax({

            url:'/zxt3.do?yesterday=' + yesterday,
            success:function (data) {

                console.log(data)
                var x = []
                var y1 = []
                var y2 = []
                var y3 = []

                for (let i = 0; i < data.length; i++) {
                    let xdata = data[i].xdata;
                    x.push(xdata)
                    let ydata1 = data[i].ydata1;
                    y1.push(ydata1)
                    let ydata2 = data[i].ydata2;
                    y2.push(ydata2)
                    let ydata3 = data[i].ydata3;
                    y3.push(ydata3)
                }

                var chartDom = document.getElementById('main');
                var myChart = echarts.init(chartDom);
                var option;

                option = {
                    title: {
                        text: 'Stacked Line'
                    },
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        data: ['确诊', '死亡', '治愈']
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    toolbox: {
                        feature: {
                            saveAsImage: {}
                        }
                    },
                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        data: x
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            name: '确诊',
                            type: 'line',
                            stack: '',
                            data: y1
                        },
                        {
                            name: '死亡',
                            type: 'line',
                            stack: '',
                            data: y2
                        },
                        {
                            name: '治愈',
                            type: 'line',
                            stack: '',
                            data: y3
                        }
                    ]
                };

                option && myChart.setOption(option);
            }
        })

    }
</script>
</html>